package cz.cvut.fel.y36pda.hs.masekji4.blanka.screens.title;

import cz.cvut.fel.y36pda.hs.masekji4.blanka.screens.enter.EnterScreen;
import net.rim.device.api.system.KeyListener;
import net.rim.device.api.ui.Keypad;
import net.rim.device.api.ui.UiApplication;

/**
 * Třída <code>TitleScreenListener</code> obsluhuje události vyvolané
 * stisknutím tlačítek během zobrazení <code>TitleScreen</code>.
 *
 * @author masekji4@fel.cvut.cz
 */
public final class TitleScreenListener implements KeyListener {
    private TitleScreen titleScreen;

    /**
     * Vytvoří instanci třídy <code>TitleScreenListener</code>.
     *
     * @param titleScreen   obrazovka
     */
    public TitleScreenListener(TitleScreen titleScreen) {
        this.titleScreen = titleScreen;
    }

    /**
     * Invoked when a sequence of zero or more keyDowns generates a character.
     * Most applications will want to use this function over the others. It will
     * be invoked when a character is generated.
     *
     * @param key       Character generated, after any effects of the ALT or
     *                  SHIFT keys and any complex keyboard mappings.
     * @param status    Status of the ALT, SHIFT and CAPS LOCK keys.
     * @param time      Number of milliseconds since the device was turned on.
     * @return          True if the event was consumed.
     */
    public boolean keyChar(char key, int status, int time) {
        return false;
    }

    /**
     * Invoked when a key has been pressed.
     * Using Keypad.key(keycode) gets the key pressed; alphabetic keys are
     * always upper case. Using keypad.status(keycode) gets the modifier key
     * status at the time of the keypress.
     * Applications such as games will want to use this funtion as it provides
     * information about which key was actually pressed, regardless of locale
     * and any key mappings applied.
     *
     * @param keycode   Key scan code of the character shown, before any effects
     *                  of the ALT or SHIFT keys.
     * @param time      Number of milliseconds since the device was turned on.
     * @return          True if the event was consumed.
     */
    public boolean keyDown(int keycode, int time) {
        switch (Keypad.key(keycode)) {
            case Keypad.KEY_SPACE:
                UiApplication.getUiApplication().pushScreen(new EnterScreen());
                return true;

            case Keypad.KEY_ESCAPE:
                System.exit(0);
                return true;

            case Keypad.KEY_MENU:
                return true;
        }

        return false;
    }

    /**
     * Invoked when a key has been repeated. Similar to keyDown.
     *
     * @param keycode   Key scan code of the character shown, before any effects
     *                  of the ALT or SHIFT keys.
     * @param time      Number of milliseconds since the device was turned on.
     * @return          True if the event was consumed.
     */
    public boolean keyRepeat(int keycode, int time) {
        return false;
    }

    /**
     * Invoked when the ALT or SHIFT status has changed.
     *
     * @param keycode   Key scan code of the character shown, before any effects
     *                  of the ALT or SHIFT keys.
     * @param time      Number of milliseconds since the device was turned on.
     * @return          True if the event was consumed.
     */
    public boolean keyStatus(int keycode, int time) {
        return false;
    }

    /**
     * Invoked when a key has been released.
     *
     * @param keycode   Key scan code of the character shown, before any effects
     *                  of the ALT or SHIFT keys.
     * @param time      Number of milliseconds since the device was turned on.
     * @return          True if the event was consumed.
     */
    public boolean keyUp(int keycode, int time) {
        return false;
    }
}